const conn = require('../../libs/DB/Conn');
const operationRecord = require("../sys/operationRecordAction");
module.exports = async function (params) {
    let userGroupList = params.groupList;
    let idList = [];
    let hasProhibitDeleteGroup = false;
    let prohibitDeleteGroupName = ``;
    userGroupList.forEach(function (data) {
        if(data.groupId !== 1 && data.groupId !== 2 && data.groupId !== 3){
            idList.push(data.groupId);
        }else{
            hasProhibitDeleteGroup = true;
            prohibitDeleteGroupName += `${data.groupName} `;
        }
    });
    if(hasProhibitDeleteGroup){return {success:false , message:`存在不允许删除的用户组: ${prohibitDeleteGroupName}`}}
    if(idList.length >0){
        let updateSql = `update user_group SET delete_sign = 2 WHERE group_id in (?)`;
        await conn(updateSql, [idList]);
        await operationRecord(params);
        return {success: true, message: '删除成功'};
    }else{
        return {success: false, message: '请选择需要删除的用户组'};
    }

};